var o = require("../../api.js"), a = getApp(), t = !1, i = !0;

Page({
    data: {
        p: 1,
        naver: "list"
    },
    onLoad: function(o) {
        a.pageOnLoad(this, o);
        var t = this;
        void 0 !== o.order_id && wx.navigateTo({
            url: "/bargain/activity/activity?order_id=" + o.order_id + "&user_id=" + o.user_id
        }), void 0 !== o.goods_id && wx.navigateTo({
            url: "/bargain/goods/goods?goods_id=" + o.goods_id + "&user_id=" + o.user_id
        }), t.loadDataFirst(o);
    },
    loadDataFirst: function(t) {
        var n = this;
        wx.showLoading({
            title: "加载中"
        }), a.request({
            url: o.bargain.index,
            type: "get",
            success: function(o) {
                0 == o.code && (n.setData(o.data), n.setData({
                    p: 2
                }), o.data.goods_list.length > 0 && (i = !1));
            },
            complete: function(o) {
                void 0 === t.order_id && wx.hideLoading(), wx.stopPullDownRefresh();
            }
        });
    },
    onReady: function() {
        a.pageOnReady(this);
    },
    onShow: function() {
        a.pageOnShow(this);
    },
    onHide: function() {
        a.pageOnHide(this);
    },
    onUnload: function() {
        a.pageOnUnload(this);
    },
    onPullDownRefresh: function() {
        this.loadDataFirst({});
    },
    onReachBottom: function() {
        i || this.loadData();
    },
    loadData: function() {
        if (!t) {
            t = !0, wx.showLoading({
                title: "加载中"
            });
            var n = this, e = n.data.p;
            a.request({
                url: o.bargain.index,
                data: {
                    page: e
                },
                success: function(o) {
                    if (0 == o.code) {
                        var a = n.data.goods_list;
                        0 == o.data.goods_list.length && (i = !0), a = a.concat(o.data.goods_list), n.setData({
                            goods_list: a,
                            p: e + 1
                        });
                    } else n.showToast({
                        title: o.msg
                    });
                },
                complete: function(o) {
                    wx.hideLoading(), t = !1;
                }
            });
        }
    },
    goToGoods: function(o) {
        var a = o.currentTarget.dataset.index;
        wx.navigateTo({
            url: "/bargain/goods/goods?goods_id=" + a
        });
    },
    onShareAppMessage: function() {
        return {
            path: "/bargain/list/list?user_id=" + this.data.__user_info.id,
            success: function(o) {}
        };
    }
});